home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 May
/
EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso
/
earcd
/
gfx
/
fract
/
lfracs.lha
/
LFracs-Source.lha
/
LFracs-Source
/
LFracs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-06
|
27KB
|
677 lines
/*****************************************************************************/
/* LFracs.c Programm zum Zeichnen von L-Fraktalen */
/*****************************************************************************/
/*** Includes ****************************************************************/
#include "StdInc.h" /* Enthält alle wichtigen C-Include-Dateien */
#include "StdFuncs.h" /* Enthält open_libs,close_libs,open_window,cls */
#include "GuiFuncs.h" /* Enthält start_GUI,end_GUI,loop_GUI, */
/* start_busy,end_busy,fill_tag, */
/* make_text,make_gadget,make_req, */
/* get_gadadr,get_STGADinfo,set_STGADinfo, */
/* add_menu,init_menu,destroy_menu */
/* destroy_gadlist,destroy_req, */
/* open_catalog,get_catstr,close_catalog */
#include "IoFuncs.h" /* Enthält win_print */
UBYTE vers[]="$VER: LFracs 1.0 (27.12.96)";
/*** Prototypes **************************************************************/
void do_menu(Item item,Event event);
void new_code(Item item,Event event);
void generator(Item item,Event event);
void plotter(void);
void quit(char *error_text);
void load_screen(Item item,Event event);
void save_screen(Item item,Event event);
void printer(Item item,Event event);
void load_code(Item item,Event event);
void save_code(Item item,Event event);
void dir_code(Item item,Event event);
/*** Globale Standard-Variablen **********************************************/
struct Window *Window = NULL;
struct RastPort *rp = NULL;
/*** Globale Konstanten ******************************************************/
#define AXIOMSIZE 32000L
#define STRINGSIZE 30
#define DATANAMESIZE 60
#define DEPTH_SIZE 3
#define PLOT_SIZE 4
#define CODEZAHL 7
/*** Datentypen für generator() und plotter() [siehe auch new_trigo()] *******/
struct Axiom {
UBYTE astr[AXIOMSIZE];
struct Axiom *next;
};
struct TrigoData {
float xschw,yschw;
struct TrigoData *prev,*next;
};
struct Verzweigung {
float xcoord,ycoord;
struct TrigoData *trigo;
};
/*** Weitere globale Variablen ***********************************************/
enum {PLUS=1,MINUS,
LBRACKET,RBRACKET,FORWARD,CODE1}; /* Standard Code-Bezeichner */
SHORT begdepth; /* Aktuelle Generator-Tiefe */
struct Axiom *axiom,*sax; /* Axiom, Axiom-zw.-Speicher */
/*** Menu-Data ***************************************************************/
struct Menu *menu = NULL;
enum {NEW,QUIT,DRAW,LOAD,SAVE,PRINT}; /* Menu-Items */
struct GuiMenudata project_data[2] = {{NULL,NEW,do_menu},
{NULL,QUIT,do_menu}};
struct GuiMenudata picture_data[4] = {{NULL,DRAW,do_menu},
{NULL,LOAD,load_screen},
{NULL,SAVE,save_screen},
{NULL,PRINT,printer}};
/*** Gadget- und Requester-Data **********************************************/
struct Requester new_req,plot_req; /* Requester */
struct FileRequester *file_req = NULL; /* ASL-Requester */
enum {NEW_GADLIST,PLOT_GADLIST,NEW_CONTXT,PLOT_CONTXT, /* GadTools-GLists */
NEW_OK_GAD,PLOT_OK_GAD,CANCEL_GAD,DIR_GAD,SAVE_GAD, /* Gadgets */
DEPTH_GAD,SCHW_GAD,DWIN_GAD,KOORD_GAD0,KOORD_GAD1,
WIN_GAD,NAME_GAD,AXIOM_GAD,CODE_GAD};
/*** Locale-Data (wird von GuiFuncs benötigt) ********************************/
enum {OK_STR,CANCEL_STR,RETRY_STR,DIR_STR,SAVE_STR,YES_STR,NOTYET_STR,
PROJECT_STR,NEW_STR,QUIT_STR,
PICTURE_STR,DRAW_STR,LOAD_STR,MSAVE_STR,PRINT_STR,
FILE_STR,STEP_STR,TURN_STR,STARTANGLE_STR,DEPTH_STR,STARTPT_STR,
CODEINPUT_STR,GENPIC_STR,
SELCODEFILE_STR,LOADPIC_STR,SAVEPIC_STR,
PRINTOK_STR,QUITOK_STR,OUTOFMEM_STR};
char *default_catstr[OUTOFMEM_STR+1] = {
"OK","CANCEL","RETRY","DIR","SAVE","YES","NOT YET",
"Project","New..._N","Quit_Q",
"Picture","Draw..._D","Load..._L","Save..._S","Print_P",
"File:","Step:","Turn:","Startangle:","Depth:","Startpt (x,y):",
"Code-Input:","Generate Picture:",
"Select Code-File","Load Picture","Save Picture",
"Ready to Print?","Quit really?","Out of Memory!"
};
/*** Globale Arrays **********************************************************/
UBYTE title[STRINGSIZE]; /* Window-Title */
UBYTE code[CODE1+CODEZAHL][STRINGSIZE]; /* Codes */
UBYTE code_buc[CODE1+CODEZAHL]={0,'+','-','(',')','f'}; /* Code-Bezeichner */
char code_title[CODEZAHL][10]; /* CodeGadget-Titel */
char *ok_title,*cancel_title,*save_title,*dir_title,
*schw_title,*dwin_title,*win_title,*depth_title,*koord_title;
/*****************************************************************************/
/* prod_GUI (Erzeugt alle Menus, Gadgets und Requester außer ASL-Requester) */
/*****************************************************************************/
void prod_GUI(void)
{
COUNT i;
short gadh,gadw,nam_gadx,plot_reqw;
char koord_info[PLOT_SIZE];
add_menu(&menu,get_catstr(PROJECT_STR),2,project_data);
add_menu(&menu,get_catstr(PICTURE_STR),4,picture_data);
init_menu(Window,menu);
set_gaps(14,3); gadh=5+fheight(1); gadw=fwidth(5);
nam_gadx = 20+tlength(save_title)+30+tlength("Code 5:");
make_gadlist(NEW_GADLIST,NEW_CONTXT);
make_gadget(SAVE_GAD,BUTTON_KIND,0,20,12+fheight(1),
tlength(save_title)+4,gadh,
get_catstr(SAVE_STR),NULL,0,NEW_CONTXT,save_code);
make_gadget(DIR_GAD,BUTTON_KIND,0,relX(0),relY(1),
tlength(save_title)+4,gadh,
get_catstr(DIR_STR),NULL,0,SAVE_GAD,dir_code);
make_gadget(NEW_OK_GAD,BUTTON_KIND,GACT_ENDGADGET,relX(0),relY(1)+8,
tlength(save_title)+4,3+gadh,ok_title,NULL,0,DIR_GAD,new_code);
make_gadget(NAME_GAD,STRING_KIND,0,nam_gadx,12+fheight(1),fwidth(30),gadh,
get_catstr(FILE_STR),NULL,STRINGSIZE,NEW_OK_GAD,load_code);
make_gadget(AXIOM_GAD,STRING_KIND,0,nam_gadx,relY(1),
fwidth(30),gadh,"Axiom:",NULL,STRINGSIZE,NAME_GAD,NULL);
for(i=0;i<CODEZAHL;i++) {
sprintf((char *)code_title[i],"Code %d:",(long) i+1);
make_gadget(CODE_GAD+i,STRING_KIND,0,
nam_gadx,relY(1),fwidth(30),gadh,
(char *)code_title[i],NULL,STRINGSIZE,CODE_GAD+i-1,NULL);
}
make_gadlist(PLOT_GADLIST,PLOT_CONTXT);
make_gadget(SCHW_GAD,STRING_KIND,LONGINT,10+tlength(schw_title),12+fheight(1),
gadw,gadh,schw_title,"20",PLOT_SIZE,PLOT_CONTXT,NULL);
make_gadget(DWIN_GAD,STRING_KIND,LONGINT,relX(1)+tlength(dwin_title),
relY(0),gadw,gadh,dwin_title,"90",PLOT_SIZE,SCHW_GAD,NULL);
make_gadget(WIN_GAD,STRING_KIND,LONGINT,relX(1)+tlength(win_title),
relY(0),gadw,gadh,win_title,"0",PLOT_SIZE,DWIN_GAD,NULL);
make_gadget(DEPTH_GAD,STRING_KIND,LONGINT|GACT_ENDGADGET,
10+tlength(depth_title),relY(1)+3,fwidth(4),gadh,
depth_title,NULL,DEPTH_SIZE,WIN_GAD,generator);
sprintf((char *)koord_info,"%d",OScanWidth/2);
make_gadget(KOORD_GAD0,STRING_KIND,LONGINT,relX(1)+tlength(koord_title),relY(0),
gadw,gadh,koord_title,koord_info,PLOT_SIZE,DEPTH_GAD,NULL);
sprintf((char *)koord_info,"%d",OScanHeight/2);
make_gadget(KOORD_GAD1,STRING_KIND,LONGINT,relX(1)-12,relY(0),
gadw,gadh,NULL,koord_info,PLOT_SIZE,KOORD_GAD0,NULL);
make_gadget(PLOT_OK_GAD,BUTTON_KIND,GACT_ENDGADGET,35,relY(1)+10,
gadw,2+gadh,ok_title,NULL,0,KOORD_GAD1,generator);
make_gadget(CANCEL_GAD,BUTTON_KIND,GACT_ENDGADGET,40+fwidth(20),relY(0),
tlength(cancel_title)+16,2+gadh,cancel_title,NULL,0,PLOT_OK_GAD,NULL);
make_req(&new_req,(OScanWidth-fwidth(30)-nam_gadx-16)/2,
OScanHeight/2-fheight(3+CODEZAHL)/2-4*CODEZAHL-20,
fwidth(30)+nam_gadx+16,40+8*CODEZAHL+fheight(3+CODEZAHL),
NEW_GADLIST,make_text(get_catstr(CODEINPUT_STR),10,5,1,NULL),0);
plot_reqw = 20+tlength(schw_title)+tlength(dwin_title)+tlength(win_title)+
gadw*3+14*2;
make_req(&plot_req,(OScanWidth-plot_reqw)/2,(OScanHeight-fheight(4)-64)/2,
plot_reqw,fheight(4)+64,PLOT_GADLIST,
make_text(get_catstr(GENPIC_STR),10,5,1,NULL),0);
}
void activate_gad(USHORT gad_id,struct Requester *req)
{ActivateGadget(get_gadadr(gad_id),Window,req);}
void do_menu(Item item,Event event)
{
switch(item) {
case QUIT: if(bool_request(Window,get_catstr(QUITOK_STR),
get_catstr(YES_STR),get_catstr(NOTYET_STR)))
quit(NULL);
break;
case NEW: show_req(&new_req,Window); activate_gad(NAME_GAD,&new_req);break;
case DRAW: show_req(&plot_req,Window); activate_gad(DEPTH_GAD,&plot_req);break;
}
}
void std_title(void)
{
sprintf((char *)title,"LFracs: %s",get_STGADinfo(NAME_GAD));
SetTitle(Window,title);
}
/*****************************************************************************/
/* init_locale (Öffnet Locale-Catalog und liest lokalisierte Strings aus) */
/*****************************************************************************/
void init_locale(void)
{
open_catalog("LFracs.catalog",default_catstr);
project_data[0].name = get_catstr(NEW_STR);
project_data[1].name = get_catstr(QUIT_STR);
picture_data[0].name = get_catstr(DRAW_STR);
picture_data[1].name = get_catstr(LOAD_STR);
picture_data[2].name = get_catstr(MSAVE_STR);
picture_data[3].name = get_catstr(PRINT_STR);
ok_title = get_catstr(OK_STR); cancel_title = get_catstr(CANCEL_STR);
save_title = get_catstr(SAVE_STR); dir_title = get_catstr(DIR_STR);
schw_title = get_catstr(STEP_STR); dwin_title = get_catstr(TURN_STR);
depth_title = get_catstr(DEPTH_STR); koord_title = get_catstr(STARTPT_STR);
win_title = get_catstr(STARTANGLE_STR);
}
/*****************************************************************************/
/* Main() (Hauptprogramm - Erzeugt Window, Menüs..., startet Main-Loop) */
/*****************************************************************************/
void main(void)
{
open_libs(INTUITION_LIB|GRAPHICS_LIB|MATHFFP_LIB|MATHTRANS_LIB|
GADTOOLS_LIB|ASL_LIB|UTILITY_LIB|LOCALE_LIB);
init_locale(); start_GUI();
Window = open_window(0,fheight(1)+3,OScanWidth,OScanHeight-fheight(1)-3,
"LFracs",WFLG_ACTIVATE|WFLG_CLOSEGADGET|
WFLG_DRAGBAR|WFLG_HASZOOM|WFLG_DEPTHGADGET,
IDCMP_CLOSEWINDOW|IDCMP_GADGETUP|IDCMP_MENUPICK|
IDCMP_NEWSIZE,NULL);
if(Window==NULL) quit("Couldn't open the Main-Window");
prod_GUI();
file_req = (struct FileRequester *) AllocAslRequestTags(ASL_FileRequest,
ASL_Dir,"FracsCodes",TAG_END);
rp=Window->RPort;
SetDrMd(rp,JAM1);
SetAPen(rp,1L);
axiom = (struct Axiom *) malloc(sizeof(struct Axiom));
sax = (struct Axiom *) malloc(sizeof(struct Axiom));
if((axiom==NULL)||(sax==NULL)) quit(get_catstr(OUTOFMEM_STR));
else {axiom->next=NULL; sax->next=NULL;}
show_req(&new_req,Window); /* Rufe Eingabe-Requester auf */
activate_gad(NAME_GAD,&new_req);
loop_GUI(Window); /* und warte auf Antwort */
quit(NULL); /* MainLoop-Ende => Quit */
}
/*****************************************************************************/
/* code_translate (Übersetzt Eingabe-Codestrings in eine kompaktere Form) */
/*****************************************************************************/
void code_translate(UBYTE *code_str)
{
COUNT i;
while(*code_str!=0) {
for(i=PLUS;i<=FORWARD+CODEZAHL;i++)
if(code_buc[i]==*code_str) {*code_str=(UBYTE) i; break;}
if(i>FORWARD+CODEZAHL) *code_str=0;
code_str++;
}
}
/*****************************************************************************/
/* new_code (Bearbeitet User-Eingaben im Eingabe-Requester) */
/*****************************************************************************/
void new_code(Item item,Event event)
{
COUNT i;
BOOL newfwd = FALSE;
UBYTE *gad_info;
begdepth=1; set_STGADinfo(DEPTH_GAD,(UBYTE *) ""); std_title();
for(i=0;i<=FORWARD;i++) {code[i][0]=i; code[i][1]=0;}
for(i=0;i<CODEZAHL;i++) {
gad_info=get_STGADinfo(CODE_GAD+i);
code_buc[CODE1+i]=*gad_info;
if(*gad_info!=0) strcpy((char *)code[CODE1+i],(char *)gad_info+2);
else strcpy((char *)code[CODE1+i],"");
if(*gad_info=='f') {
newfwd=TRUE; strcpy((char *)code[FORWARD],(char *)code[CODE1+i]);
}
}
if(newfwd) code_translate(code[FORWARD]);
for(i=CODE1;i<CODE1+CODEZAHL;i++) code_translate(code[i]);
show_req(&plot_req,Window); /* Rufe Zeichnen-Requester auf */
activate_gad(DEPTH_GAD,&plot_req);
}
/*****************************************************************************/
/* ..._axiom() - Funktionen (Um den Speicherbedarf der axiom/sax-Strings zu */
/* halbieren, werden in ein Byte zwei Codezeichen */
/* [es gibt <=5+CODEZAHL<16 versch.] geschrieben. */
/* Die folgenden Funktionen erleichtern den Umgang */
/* mit diesen besonderen Strings) */
/*****************************************************************************/
UBYTE get_nextaxiom(UBYTE **aptr, BOOL *right_part)
{
*right_part = !(*right_part);
if(*right_part) return ((**aptr)&15);
else {(*aptr)++; return ((**aptr)>>4);}
}
void set_axiom(UBYTE **aptr, BOOL *right_part, UBYTE *scode)
{
UBYTE *code_ptr;
code_ptr=scode;
if(*right_part) {
**aptr = (**aptr) | *code_ptr;
code_ptr++; (*aptr)++;
}
while(*code_ptr) {
**aptr = ((*code_ptr)<<4) | *(++code_ptr);
if(*code_ptr==0) {*right_part=TRUE; return;}
(*aptr)++; code_ptr++;
}
**aptr=0; *right_part=FALSE;
}
/*****************************************************************************/
/* destroy_axiom (Gibt den Speicher der Axiom-Liste aptr wieder frei) */
/*****************************************************************************/
void destroy_axiom(struct Axiom *aptr)
{
if(aptr!=NULL) {destroy_axiom(aptr->next); free(aptr);}
}
/*****************************************************************************/
/* generator (Generiert das L-Fractal auf dem String axiom aus den Codes) */
/*****************************************************************************/
void generator(Item item,Event event)
{
COUNT i;
struct Axiom *axiom_act,*sax_act,*hptr;
UBYTE *axiom_ptr,*sax_ptr,*sax_max,trans_str[STRINGSIZE],avalue;
SHORT enddepth;
BOOL axiom_rpart,sax_rpart;
enddepth=(SHORT) atoi((char *)get_STGADinfo(DEPTH_GAD));
if(enddepth<begdepth-1) begdepth=1;
if(begdepth==1) {
strcpy((char *)trans_str,(char *)get_STGADinfo(AXIOM_GAD));
code_translate(trans_str);
axiom_ptr=axiom->astr; axiom_rpart=FALSE;
set_axiom(&axiom_ptr,&axiom_rpart,trans_str);
destroy_axiom(axiom->next); axiom->next=NULL;
destroy_axiom(sax->next); sax->next=NULL;
}
while(begdepth <= enddepth)
{
sprintf((char *)title,"Generating %d of %d",(long) begdepth,(long) enddepth);
SetTitle(Window,title);
sax_act = sax; sax_ptr = sax_act->astr;
sax_rpart=FALSE; *sax_ptr=0;
sax_max = sax_ptr+AXIOMSIZE-STRINGSIZE;
for(axiom_act=axiom;axiom_act!=NULL;axiom_act=axiom_act->next) {
axiom_ptr=axiom_act->astr; axiom_rpart=FALSE;
avalue = (*axiom_ptr)>>4;
while(avalue) {
set_axiom(&sax_ptr,&sax_rpart,code[avalue]);
if(sax_ptr > sax_max) {
if(sax_act->next == NULL) {
while(!(sax_act->next = (struct Axiom *) malloc(sizeof(struct Axiom))))
if(!bool_request(Window,get_catstr(OUTOFMEM_STR),
get_catstr(RETRY_STR),cancel_title))
return();
sax_act->next->next = NULL;
}
sax_act = sax_act->next; sax_rpart=FALSE;
sax_ptr = sax_act->astr; *sax_ptr=0;
sax_max = sax_ptr+AXIOMSIZE-STRINGSIZE;
}
if(read_message(Window)) {std_title();return();}
avalue=get_nextaxiom(&axiom_ptr,&axiom_rpart);
}
}
hptr=sax; sax=axiom; axiom=hptr;
begdepth++;
}
std_title(); plotter();
}
/*****************************************************************************/
/* new_trigo u. del_trigo (Werden v. plotter() zum Werte-Speichern benutzt) */
/*****************************************************************************/
struct TrigoData *new_trigo(SHORT win, SHORT schw)
{
struct TrigoData *trigo;
trigo=(struct TrigoData *) malloc(sizeof(struct TrigoData));
trigo->xschw = (float)schw*(float)cos((double)(win*PI/180.0))*0.1;
trigo->yschw = (float)schw*(float)sin((double)(win*PI/180.0))*0.1;
return (trigo);
}
void del_trigo(struct TrigoData *trigo)
{
struct TrigoData *tri_ptr,*tri_next;
if(trigo!=NULL) {
tri_ptr=trigo->next; trigo->next=NULL;
while(tri_ptr!=NULL) {
tri_next=tri_ptr->next;
free(tri_ptr); tri_ptr=tri_next;
}
}
}
/*****************************************************************************/
/* plotter (Zeichnet das L-Fractal nach dem String axiom aus generator()) */
/*****************************************************************************/
void plotter(void)
{
struct Axiom *axiom_act;
struct Verzweigung node[150],*node_ptr;
struct TrigoData *tri_first,*tri_ptr,*tri_old;
UBYTE *axiom_ptr,avalue;
SHORT schw,dwin,startwin,winkel;
float x,y;
BOOL rpart;
node_ptr = node;
dwin = (SHORT) atoi((char *)get_STGADinfo(DWIN_GAD));
schw = (SHORT) atoi((char *)get_STGADinfo(SCHW_GAD));
startwin = (SHORT) atoi((char *)get_STGADinfo(WIN_GAD));
x = (float) atoi((char *)get_STGADinfo(KOORD_GAD0));
y = (float) atoi((char *)get_STGADinfo(KOORD_GAD1));
dwin=(dwin+360)%360; startwin=(startwin+360)%360;
tri_first=new_trigo(startwin,schw); tri_old=tri_first;
for(winkel=startwin+dwin;(winkel%360)!=startwin;winkel=(winkel+dwin)%360) {
tri_ptr=new_trigo(winkel,schw);
tri_ptr->prev=tri_old; tri_old->next=tri_ptr;
tri_old=tri_ptr;
}
tri_old->next=tri_first; tri_first->prev=tri_old;
tri_ptr=tri_first;
SetTitle(Window,(UBYTE *) "Drawing..."); cls(Window);
Move(rp,(long) x,(long) y);
x/=Scale;
for(axiom_act=axiom;axiom_act!=NULL;axiom_act=axiom_act->next) {
rpart=FALSE; axiom_ptr=axiom_act->astr;
avalue = (*axiom_ptr)>>4;
while(avalue)
{
switch (avalue) {
case PLUS: tri_ptr=tri_ptr->next; break;
case MINUS: tri_ptr=tri_ptr->prev; break;
case FORWARD: x+=tri_ptr->xschw;
y-=tri_ptr->yschw;
Draw(rp,(long) (x*Scale),(long) y); break;
case LBRACKET: node_ptr->xcoord=x; node_ptr->ycoord=y;
node_ptr->trigo=tri_ptr;
node_ptr++; break;
case RBRACKET: node_ptr--;
x=node_ptr->xcoord; y=node_ptr->ycoord;
tri_ptr=node_ptr->trigo;
Move(rp,(long) (x*Scale),(long) y); break;
}
if(read_message(Window)) {del_trigo(tri_ptr); std_title(); return();}
avalue=get_nextaxiom(&axiom_ptr,&rpart);
}
}
del_trigo(tri_ptr); std_title();
}
/*****************************************************************************/
/* quit (Beendet das Programm - Vorher werden alle dyn. Daten gelöscht) */
/*****************************************************************************/
void quit(char *error_text)
{
destroy_axiom(axiom); destroy_axiom(sax);
if(file_req) FreeAslRequest((APTR) file_req);
destroy_menu(Window);
if(Window) CloseWindow(Window);
destroy_gadlist(NEW_GADLIST); destroy_gadlist(PLOT_GADLIST);
destroy_req(&new_req); destroy_req(&plot_req);
end_GUI();
close_catalog();
close_libs();
if(error_text) {printf("%s\n",error_text); exit(FALSE);}
else exit(TRUE);
}
/*****************************************************************************/
/* load/save_screen (Lädt, oder speichert ein Fractal-Bild) */
/*****************************************************************************/
void load_screen(Item item,Event event)
{
COUNT x,y;
ULONG pic_handle;
UBYTE dateiname[DATANAMESIZE];
SHORT win_left,win_right,win_top;
SHORT pic_scale,color=0,pix_anzahl;
float scaler;
win_left=4; win_right=OScanWidth-5; win_top=11;
if (AslRequestTags((APTR) file_req,ASL_Dir,(ULONG)"FracsPictures",
ASL_Hail,(ULONG)get_catstr(LOADPIC_STR),
ASL_Pattern,(ULONG)"#?.lfpic",
ASL_File,0L,TAG_END))
{
sprintf((char *)dateiname,"%s/%s",
(char *) file_req->rf_Dir,(char *) file_req->rf_File);
start_busy(Window); /* Make Window Busy */
if(pic_handle=Open(dateiname,MODE_OLDFILE)) {
SetTitle(Window,(UBYTE *) "Loading...");
Read(pic_handle,&pic_scale,2L);
Read(pic_handle,&win_right,2L);
scaler=((float)Scale)/((float)pic_scale);
x=win_left-1; y=win_top;
Move(rp,win_left,win_top);
while (Read(pic_handle,&pix_anzahl,2L)) {
color = pix_anzahl & 1L;
x+=(pix_anzahl>>1);
if(color) Draw(rp,(SHORT)((x-win_left)*scaler+win_left),y);
Move(rp,(SHORT)((x+1-win_left)*scaler+win_left),y);
if(x==win_right) {
x=win_left-1; y++;
Move(rp,win_left,y);
}
}
Close(pic_handle);
}
end_busy(Window); std_title(); /* Unbusy Window */
}
}
void save_screen(Item item,Event event)
{
COUNT x,y;
ULONG pic_handle;
UBYTE dateiname[DATANAMESIZE],vorschlag[STRINGSIZE];
SHORT win_left,win_right,win_top,win_bottom;
SHORT color=0,pix_anzahl,xlast;
win_left = 4; win_right = OScanWidth-5;
win_top = 11; win_bottom = OScanHeight-3;
sprintf((char *)vorschlag,"%s%d.lfpic",get_STGADinfo(NAME_GAD),begdepth-1);
if (AslRequestTags((APTR) file_req,ASL_Dir,(ULONG)"FracsPictures",
ASL_Hail,(ULONG)get_catstr(SAVEPIC_STR),
ASL_Pattern,(ULONG)"#?.lfpic",
ASL_File,(ULONG) vorschlag,TAG_END))
{
sprintf((char *)dateiname,"%s/%s",
(char *) file_req->rf_Dir,(char *) file_req->rf_File);
start_busy(Window); /* Make Window Busy */
if(pic_handle=Open(dateiname,MODE_NEWFILE)) {
SetTitle(Window,(UBYTE *) "Saving...");
Write(pic_handle,(UBYTE *) &Scale,2L);
Write(pic_handle,(UBYTE *) &win_right,2L);
for(y=win_top;y<=win_bottom;y++) {
for(x=xlast=win_left;x<=win_right;x++)
if(color != (SHORT) ReadPixel(rp,x,y)) {
if (pix_anzahl = (x-xlast)<<1) {
pix_anzahl |= color;
Write(pic_handle,(UBYTE *) &pix_anzahl,2L);
xlast=x;
}
color=!color;
}
pix_anzahl = ((x-xlast)<<1) | color;
Write(pic_handle,(UBYTE *) &pix_anzahl,2L);
}
Close(pic_handle);
}
end_busy(Window); std_title(); /* Unbusy Window */
}
}
/*****************************************************************************/
/* printer (Druckt das momentan angezeigte Fractal) */
/*****************************************************************************/
void printer(Item item,Event event)
{
SHORT dbarheight;
if(bool_request(Window,get_catstr(PRINTOK_STR),
get_catstr(YES_STR),get_catstr(NOTYET_STR))) {
dbarheight = Window->WScreen->WBorTop + Window->WScreen->Font->ta_YSize;
SetTitle(Window,(UBYTE *) "Printing...");
start_busy(Window);
win_print(Window,(UWORD)(Window->LeftEdge+4),(UWORD)(dbarheight + 1),
(UWORD)(Window->Width-8),(UWORD)(Window->Height - dbarheight - 3),
20,YScale);
end_busy(Window); std_title();
}
}
/*****************************************************************************/
/* load_code/save_code (Lädt/Speichert den Code zu einem bestimmten Fractal) */
/*****************************************************************************/
void load_code(Item item,Event event)
{
COUNT i;
UBYTE dateiname[DATANAMESIZE],ptr[2],*gad_info;
ULONG codehandle;
sprintf((char *)dateiname,"%s/%s.code",
(char *)(file_req->rf_Dir),get_STGADinfo(NAME_GAD));
if(codehandle=Open(dateiname,MODE_OLDFILE)) {
i=0;
while(Read(codehandle,ptr,1L))
if(ptr[0]=='/') {
gad_info = get_STGADinfo(AXIOM_GAD+i);
strcpy((char *)gad_info,"");
i++;
}else strncat((char *)gad_info,(char *)ptr,1L);
for(;i<=CODEZAHL;i++) set_STGADinfo(AXIOM_GAD+i,(UBYTE *) "");
Close(codehandle);
}
RefreshGadgets(get_gadadr(AXIOM_GAD),Window,&new_req);
}
void save_code(Item item,Event event)
{
COUNT i;
UBYTE dateiname[DATANAMESIZE],*ptr;
ULONG codehandle;
sprintf((char *)dateiname,"FracsCodes/%s.code",get_STGADinfo(NAME_GAD));
if(codehandle=Open(dateiname,MODE_NEWFILE)) {
for(i=0;i<=CODEZAHL;i++) {
ptr=(UBYTE *) get_STGADinfo(AXIOM_GAD+i);
if(*ptr!=0) {
Write(codehandle,"/",1L);
Write(codehandle,ptr,(long) strlen((char *)ptr));
}
}
Close(codehandle);
}
}
/*****************************************************************************/
/* dir_code (Aus der Liste aller bereits gespeicherten Fractal-Code-Files */
/* kann ein bestimmtes File ausgewählt werden) */
/*****************************************************************************/
void dir_code(Item item,Event event)
{
UBYTE *gad_info;
if (AslRequestTags((APTR)file_req,ASL_Dir,(ULONG)"FracsCodes",
ASL_Hail,(ULONG)get_catstr(SELCODEFILE_STR),
ASL_Pattern,(ULONG)"#?.code",
ASL_File,(ULONG)"#?.code",TAG_END))
{
gad_info = get_STGADinfo(NAME_GAD);
strcpy((char *)gad_info,(char *)file_req->rf_File);
gad_info[strlen((char *)file_req->rf_File)-5] = 0; /*Schneide .code ab*/
RefreshGadgets(get_gadadr(NAME_GAD),Window,&new_req);
load_code(GF_NULL,GF_NULL);
}
}